Ext.define('App.inventory.productList', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.productListPanel',
    layout: 'fit',
    autoScroll: true,
    autoHeight: true,
    initComponent: function () {
        var grid, selModel, searchFlds;
        searchFlds = new Ext.util.MixedCollection();
        searchFlds.add('name', new Ext.form.TextField({
            name: 'name',
            dataIndex: 'name',
            fieldLabel: '产品名称'
        }));

        var toolbar = new Ext.Toolbar({
            enableOverflow: true,
            items: [
                {
                    text: "新增",
                    iconCls: 'addIcon',
                    handler: function () {
                        var productForm = Ext.create('App.inventory.productForm');
                        productForm.show();
                        productForm.setTitle('新增');
                    }
                },
                '-',
                {
                    text: "编辑",
                    iconCls: 'editIcon',
                    handler: function () {
                        var sm = Ext.getCmp('productGrid').getSelectionModel();
                        var records = sm.getSelection();
                        if (records.length <= 0) {
                            Ext.Msg.alert('错误', "未选中记录，不能修改！");
                            return;
                        }
                        var productForm = Ext.create('App.inventory.productForm');
                        productForm.show();
                        productForm.setTitle('编辑');
                        var data = records[0].data;
                        productForm.down('form').getForm().loadRecord(records[0]);

                    }
                },
                '-',
                {
                    text: "删除",
                    iconCls: 'deleteIcon',
                    handler: function () {
                        Ext.getCmp('productGrid').deleteRecord();
                    }
                },
                "->",
                searchFlds.get('endname'),
                ,
                {
                    text: "搜索",
                    iconCls: 'searchIcon',
                    handler: function () {
                        grid.load();
                    }
                }
            ]
        });
        grid = Ext.create('gridView', {
            remoteSort: true,
            forceFit: true,
            gridId: 'productGrid',
            checkboxSelectionModel: true,
            searchFlds: searchFlds,
            entityClassName: 'crm.rover.inventory.entity.Product',
            queryUrl: 'productController/query.action',
            deleteUrl: 'productController/delete.action',
            recordPk: [ "id" ],
            tbar: toolbar
        });
        selModel = grid.getSelectionModel();
        selModel.on('rowselect', function (selModel, rowIndex, record) {
            }
        );
        Ext.apply(this, {items: [grid]});
        this.callParent(arguments);
    }, destroy: function () {
        Ext.getCmp('productList').destroy();
        this.destroy();
    }
});